using AndyPike.Commons;
using AndyPike.Commons.Extensions;
using AndyPike.Snowflake.Core.Exceptions;

namespace AndyPike.Snowflake.Core.Messages
{
    public class RegistrationMessage : IMessage
    {
        private string password;

        public string UserName { get; set; }
        public string Email { get; set; }

        public string Password
        {
            get { return password != null ? password.ToMD5() : password; }
            set { password = value; }
        }

        public virtual void Validate()
        {
            if(UserName == null || UserName.Length < 4)
                throw new InvalidUserNameException();

            if (Password == null || Password.Length < 6)
                throw new InvalidPasswordException();

            if(Email == null || !Email.IsValidEmailFormat())
                throw new InvalidEmailException();
        }
    }
}